//
//  Project_Step1ViewController.m
//  CMVRFForIOS
//
//  Created by zhangnorman on 15/4/4.
//  Copyright (c) 2015年 hvacapp. All rights reserved.
//

#import "Project_Step1ViewController.h"
#import "DefaultStyleTableViewCell.h"
#import "Project_TabViewController.h"
#import "BottomActionView.h"
#import "EditorTableViewCell.h"
//#import <TPKeyboardAvoidingTableView.h>
#import "ProvinceData.h"
#import "Project_Step2ViewController.h"
#import "ProjectSelectTempletViewController.h"
#import "SelectionNationViewController.h"
#import "SelectProvinceViewController.h"
#import "SelectCityViewController.h"
#import "CommonResponse.h"
#import <MBProgressHUD.h>
#import "ProjectManager.h"
#import "UITapView.h"
#import "AppDelegate.h"
#import "JFCityViewController.h"
#import "ProjectCalc.h"
#import <CustomIOSAlertView.h>
#import "CheckBoxView.h"
#import "TerminalTypeTableViewCell.h"
#import "ProjectContentViewController.h"


@interface Project_Step1ViewController ()<JFCityViewControllerDelegate> {
}

@property (nonatomic,strong) UITableView *tableView;
@property (nonatomic,strong) BottomActionView *footerView;

@property (nonatomic,copy) NSString *city_id;
@property (nonatomic,copy) NSString *city_name;
@property (nonatomic,copy) NSString *owner_name;
@property (nonatomic,copy) NSString *owner_tel;
@property (nonatomic,copy) NSString *power_type;
@property (nonatomic,copy) NSString *project_name;
@property (nonatomic,copy) NSString *requirement;
@property (nonatomic,assign) double area;
@property (nonatomic,assign) int house_floors;
@property (nonatomic,assign) double floor_height;

@end

@implementation Project_Step1ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.title = @"项目信息";
    // Do any additional setup after loading the view.
    [self initData];
    [self setupBaseViews];
    [self setupViews];
}

- (void)viewDidAppear:(BOOL)animated {
    [super viewDidAppear:animated];
    [self.footerView updateCenterTitle:[[ProjectManager manager]getCurrentStepInfo]];
}

- (void)copyProjectData {
    self.city_id = kProject.city_id;
    self.city_name = kProject.city_name;
    self.owner_name = kProject.owner_name;
    self.owner_tel = kProject.owner_tel;
    self.power_type = kProject.power_type;
    self.project_name = kProject.project_name;
    self.requirement = kProject.requirement;
    self.area = kProject.area;
    self.house_floors = kProject.house_floors;
    self.floor_height = kProject.floor_height;
}

#pragma mark - 初始化视图
- (void)setupBaseViews {
    //自定义返回按钮
    UIBarButtonItem *backBtn = [[UIBarButtonItem alloc] initWithTitle:@"项目" style:UIBarButtonItemStyleDone target:self action:@selector(onBackToProject)];
    self.navigationItem.leftBarButtonItem = backBtn;
    
    //底部的上一步，下一步按钮
    self.footerView = [[BottomActionView alloc]initWithFrame:CGRectMake(0, self.view.height - KAction_Bar_Height - kNavigation_Bar_Height - kStatus_Bar_Height, kScreen_Width, KAction_Bar_Height)];
    if (iPhone_X) {
        self.footerView.y -= 34;
    }
    @weakObj(self);
    [self.footerView addRightBtnBlock:^(id obj) {
        if ([Weakself checkProjectInfo] == NO) {
            return;
        }
        
        if ([Tools isEmpty:Weakself.project_id]) {
            //还没有创建项目
            [Weakself createProject:^(BOOL result) {
                if (result) {
                    [[ProjectManager manager]goNextPage];
                    if (kProject.template_bind == 0) {
                        ProjectSelectTempletViewController *vc = [ProjectSelectTempletViewController new];
                        [Weakself.navigationController pushViewController:vc animated:YES];
                    } else {
                        Project_Step2ViewController *vc = [Project_Step2ViewController new];
                        [Weakself.navigationController pushViewController:vc animated:YES];
                    }
                } else {
                    [Tools showMessageCenter:@"创建项目失败！"];
                }
            }];
        }
        else {
            [Weakself modifyProject:^(BOOL result) {
                if (result) {
                    [[ProjectManager manager]goNextPage];
                    [[ProjectManager manager]setTemplateBind:kProject.template_bind];
                    if (kProject.template_bind == 0) {
                        ProjectSelectTempletViewController *vc = [ProjectSelectTempletViewController new];
                        [Weakself.navigationController pushViewController:vc animated:YES];
                    } else {
                        Project_Step2ViewController *vc = [Project_Step2ViewController new];
                        [Weakself.navigationController pushViewController:vc animated:YES];
                    }
                } else {
                    [Tools showMessageCenter:@"修改项目失败！"];
                }
            }];
        }
    }];
    [self.footerView setLeftBtnTitle:@"" andRightBtnTitle:@"下一步" andCenterTitle:[[ProjectManager manager]getCurrentStepInfo]];
    [self.view addSubview:self.footerView];
}

- (void)setupViews{
    //列表
    self.tableView = [[UITableView alloc] initWithFrame:[UIView frameWithOutNavBottom] style:UITableViewStylePlain];
    [self.tableView registerClass:[EditorTableViewCell class] forCellReuseIdentifier:@"edit"];
    [self.tableView registerClass:[TerminalTypeTableViewCell class] forCellReuseIdentifier:@"ter"];
    self.tableView.backgroundColor = CM_TABLE_BG_COLOR;
    self.tableView.delegate = self;
    self.tableView.dataSource = self;
    //去掉多余的分割线
    self.tableView.tableFooterView = [[UIView alloc] initWithFrame:CGRectZero];
    [self.view addSubview:self.tableView];
    //下拉刷新
    self.tableView.mj_header = [MJRefreshNormalHeader headerWithRefreshingBlock:^{
        // 进入刷新状态后会自动调用这个block
        [self loadData];
    }];
    [self.tableView.mj_header beginRefreshing];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

#pragma mark - 事件响应函数
/**
 *  直接跳转到项目页面
 */
-(void) onBackToProject{
    //返回到首页
    for (UIViewController *tmp in self.navigationController.viewControllers) {
        if ([tmp isKindOfClass:[Project_TabViewController class]]) {
            [(Project_TabViewController*)tmp refreshData];
            [self.navigationController popToViewController:tmp animated:YES];
        }
    }
}


#pragma mark - 加载数据
/**
 *  初始化数据
 */
- (void)initData {
    //初始化上一步下一步信息中的步数
    kProject = nil;
    if ([Tools isEmpty:self.project_id]) {
        [[ProjectManager manager]initStepInfo:YES];
    } else {
        [[ProjectManager manager]initStepInfo:NO];
    }
    
}

- (void)loadData {
    if (![Tools isEmpty:self.project_id]) {
        //修改项目
        NSMutableDictionary *param = [NSMutableDictionary dictionary];
        [param setValue:self.project_id forKey:@"project_id"];
        
        [HttpClient getWithUrl:HTTP_GET_PROJECT_INFO token:[[AccountManager manager]token] paramDic:param resultClass:[ProjectData class] success:^(ProjectData *obj) {
            //下拉刷新
            [self.tableView.mj_header endRefreshing];
            kProject = obj;
            kProject.name = self.username;
            [self copyProjectData];
            [[ProjectManager manager]setTemplateBind:kProject.template_bind];
            [[ProjectManager manager]updateTotalSteps];
            [self.footerView updateCenterTitle:[[ProjectManager manager]getCurrentStepInfo]];
            if ([Tools isEmpty:kProject.main_equip_series]) {
                kProject.coeff_input = 1;
            }
            [self.tableView reloadData];
        } failure:^(NSError *error) {
            [self.tableView.mj_header endRefreshing];
            CMLog(@"获取项目失败：%@", error);
        }];
    } else {
        ProjectData *data = [ProjectData new];
        NSDictionary *city = [Tools getApplicationData:CityName];
        if (city != nil) {
            NSString *name = [city objectForKey:@"city"];
            NSString *guid = [city objectForKey:@"id"];
            if (![Tools isEmpty:name]) {
                data.city_name = name;
            }
            if (![Tools isEmpty:guid]) {
                data.city_id = guid;
            }
        }
        data.house_floors = 3;
        data.floor_height = 3;
        data.requirement = @"空调";
        data.terminal_type = @"风机盘管+地暖";
        data.requirement = @"空调+采暖";
        data.power_type = @"全部设备";
        kProject = data;
        kProject.name = [AccountManager manager].account.username;
        [self copyProjectData];
        [self.tableView.mj_header endRefreshing];
        [self.tableView reloadData];
    }
    dispatch_async(dispatch_get_main_queue(), ^{
        //加载室内机
        kProject.fcuEquips = [[ProjectCalc instance] calcAllSnjEquip];
        
    });
}

- (void)createProject:(void (^)(BOOL))result{
    //参数
    NSMutableDictionary *params = [NSMutableDictionary dictionary];
    [params setValue:@(self.area) forKey:@"area"];
    [params setValue:@(self.house_floors) forKey:@"house_floors"];
    [params setValue:@(self.floor_height) forKey:@"floor_height"];
    [params setValue:self.city_id forKey:@"city_id"];
    [params setValue:self.city_name forKey:@"city_name"];
    [params setValue:self.owner_name forKey:@"owner_name"];
    [params setValue:self.owner_tel forKey:@"owner_tel"];
    [params setValue:self.power_type forKey:@"power_type"];
    [params setValue:self.project_name forKey:@"project_name"];
    [params setValue:self.requirement forKey:@"requirement"];
    [params setValue:kProject.terminal_type forKey:@"terminal_type"];
    [MBProgressHUD showMessage:@"数据提交中..." toView:self.view];
    [HttpClient postWithUrl:HTTP_POST_PROJECT_NEW token:[AccountManager manager].token paramDic:params resultClass:[ProjectData class] success:^(ProjectData *obj) {
        [MBProgressHUD hideHUDForView:self.view];
        self.project_id = obj.project_id;
        kProject.project_id = obj.project_id;
        kProject.city_id = self.city_id;
        kProject.city_name = self.city_name;
        kProject.owner_name = self.owner_name;
        kProject.owner_tel = self.owner_tel;
        kProject.power_type = self.power_type;
        kProject.project_name = self.project_name;
        kProject.requirement = self.requirement;
        kProject.area = self.area;
        kProject.house_floors = self.house_floors;
        kProject.floor_height = self.floor_height;
        kProject.coeff_input = 1;
        [self.tableView reloadRowsAtIndexPaths:indexPathObj(2, 0) withRowAnimation:UITableViewRowAnimationAutomatic];
        result(YES);
    } failure:^(NSError *error) {
        [MBProgressHUD hideHUDForView:self.view];
        result(NO);
    }];
    
}

- (BOOL)checkModified {
    if (self.area != kProject.area) {
        return YES;
    }
    if (self.house_floors != kProject.house_floors) {
        return YES;
    }
    if (self.floor_height != kProject.floor_height) {
        return YES;
    }
    if (![self.city_id isEqualToString:kProject.city_id]) {
        return YES;
    }
    if (![self.city_name isEqualToString:kProject.city_name]) {
        return YES;
    }
    if (![self.project_name isEqualToString:kProject.project_name]) {
        return YES;
    }
    if (![self.power_type isEqualToString:kProject.power_type]) {
        return YES;
    }
    if (![self.requirement isEqualToString:kProject.requirement]) {
        return YES;
    }
    if ([Tools isEmpty:self.owner_tel]) {
        if (![Tools isEmpty:kProject.owner_tel]) {
            return YES;
        }
    } else {
        if ([Tools isEmpty:kProject.owner_tel]) {
            return YES;
        } else if (![self.owner_tel isEqualToString:kProject.owner_tel]) {
            return YES;
        }
    }
    if ([Tools isEmpty:self.owner_tel]) {
        if (![Tools isEmpty:kProject.owner_tel]) {
            return YES;
        }
    } else {
        if ([Tools isEmpty:kProject.owner_tel]) {
            return YES;
        } else if (![self.owner_tel isEqualToString:kProject.owner_tel]) {
            return YES;
        }
    }
    return NO;
}

- (void)modifyProject:(void (^)(BOOL))result{
    //参数
    if (![self checkModified]) {
        result(YES);
        return;
    }
    NSMutableDictionary *params = [NSMutableDictionary dictionary];
    [params setValue:@(self.area) forKey:@"area"];
    [params setValue:@(self.house_floors) forKey:@"house_floors"];
    [params setValue:@(self.floor_height) forKey:@"floor_height"];
    [params setValue:self.city_id forKey:@"city_id"];
    [params setValue:self.city_name forKey:@"city_name"];
    [params setValue:self.owner_name forKey:@"owner_name"];
    [params setValue:self.owner_tel forKey:@"owner_tel"];
    [params setValue:self.power_type forKey:@"power_type"];
    [params setValue:self.project_name forKey:@"project_name"];
    [params setValue:self.requirement forKey:@"requirement"];
    [params setValue:kProject.terminal_type forKey:@"terminal_type"];
    [params setValue:kProject.project_id forKey:@"project_id"];
    [MBProgressHUD showMessage:@"数据提交中..." toView:self.view];
    [HttpClient postWithUrl:HTTP_POST_PROJECT_EDIT token:[AccountManager manager].token paramDic:params resultClass:[ProjectData class] success:^(ProjectData *obj) {
        [MBProgressHUD hideHUDForView:self.view];
        kProject.rooms = [obj.rooms mutableCopy];
        kProject.city_id = self.city_id;
        kProject.city_name = self.city_name;
        kProject.owner_name = self.owner_name;
        kProject.owner_tel = self.owner_tel;
        kProject.power_type = self.power_type;
        kProject.project_name = self.project_name;
        kProject.requirement = self.requirement;
        kProject.area = self.area;
        kProject.house_floors = self.house_floors;
        kProject.floor_height = self.floor_height;
        [self copyProjectData];
        result(YES);
    } failure:^(NSError *error) {
        [MBProgressHUD hideHUDForView:self.view];
        result(NO);
    }];
    
}

/**
 *  检查项目信息输入是否合理
 *
 *  @return 是否通过了验证
 */
- (BOOL)checkProjectInfo {
    if ([Tools isEmpty:self.city_name]) {
        [Tools showMessageCenter:@"项目地点不能为空！"];
        return NO;
    }
    if ([Tools isEmpty:self.project_name]) {
        [Tools showMessageCenter:@"项目名称不能为空！"];
        return NO;
    }
    if ([Tools isEmpty:self.requirement]) {
        [Tools showMessageCenter:@"项目需求不能为空！"];
        return NO;
    }
    if (self.area <= 0) {
        [Tools showMessageCenter:@"户型面积必须大于0！"];
        return NO;
    }
    if (self.floor_height <= 0) {
        [Tools showMessageCenter:@"楼层高度必须大于0！"];
        return NO;
    }
    
    return YES;
}


#pragma mark - tableView显示设置数据
-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
    return 2;
}

-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    if (section == 0) {
        return 7;
    }
    return 2;
}

-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    EditorTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"edit"];
    cell.editorView.enabled = YES;
    if (indexPath.section == 0) {
        UITableViewCell *Selectcell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:@"SelectArea_Cell"];
        Selectcell.textLabel.textColor = CM_TABLE_TITLE_COLOR;
        Selectcell.detailTextLabel.textColor = CM_TABLE_INFO_COLOR;
        if (indexPath.row == 0) {
            if (![Tools isEmpty:self.project_name]) {
                [cell setTitleStr:@"项目名称" andColor:nil andHintStr:@"XX小区X单元xxxx房间" andInputViewIsHidden:NO andInfoStr:self.project_name andUnit:nil];
                [cell setEditorText:self.project_name];
            }
            else {
                [cell setTitleStr:@"项目名称" andColor:nil andHintStr:@"XX小区X单元xxxx房间" andInputViewIsHidden:NO andInfoStr:nil andUnit:nil];
            }
//            [cell.editorView becomeFirstResponder];
            cell.TextFiledValueBlock = ^(NSString *value) {
                self.project_name = value;
            };
            [cell setItemIsNesessory];
            return cell;
        } else if (indexPath.row == 1) {
            if (self.area > 0) {
                [cell setTitleStr:@"户型面积" andColor:nil andHintStr:@"请输入户型面积" andInputViewIsHidden:NO andInfoStr:nil andUnit:@"㎡"];
                [cell setEditorText:[NSString stringWithFormat:@"%.1f", self.area]];
            }
            else {
                [cell setTitleStr:@"户型面积" andColor:nil andHintStr:@"请输入户型面积" andInputViewIsHidden:NO andInfoStr:nil andUnit:@"㎡"];
            }
            [cell setKeyboardType:UIKeyboardTypeDecimalPad];
            cell.TextFiledValueBlock = ^(NSString *value) {
                self.area = [value doubleValue];
            };
            [cell setItemIsNesessory];
            return cell;
        } else if (indexPath.row == 3) {
            Selectcell.textLabel.text = @"建筑层数";
            if (self.house_floors == 0) {
                Selectcell.detailTextLabel.text = @"请选择";
            } else if (self.house_floors == 1){
                Selectcell.detailTextLabel.text = @"一层";
            } else if (self.house_floors == 2){
                Selectcell.detailTextLabel.text = @"二层";
            } else if (self.house_floors == 3){
                Selectcell.detailTextLabel.text = @"多层";
            }
            Selectcell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
        } else if (indexPath.row == 2) {
             [cell setTitleStr:@"楼层层高" andColor:nil andHintStr:@"请输入层高" andInputViewIsHidden:NO andInfoStr:nil andUnit:@"m"];
            if (self.floor_height > 0) {
                [cell setEditorText:[NSString stringWithFormat:@"%.1f", self.floor_height]];
            }
            [cell setKeyboardType:UIKeyboardTypeDecimalPad];
            cell.TextFiledValueBlock = ^(NSString *value) {
                self.floor_height = [value doubleValue];
            };
            [cell setItemIsNesessory];
            if ([Tools isEmpty:self.project_id]) {
                cell.editorView.enabled = YES;
            } else {
                cell.editorView.enabled = NO;
            }
            return cell;
        } else if (indexPath.row == 4) {
            Selectcell.textLabel.text = @"所在城市";
            if ([Tools isEmpty:self.city_name]) {
                Selectcell.detailTextLabel.text = @"请选择";
            } else {
                Selectcell.detailTextLabel.text = self.city_name;
            }
            Selectcell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
        }
        else if (indexPath.row == 5) {
            Selectcell.textLabel.text = @"项目需求";
            if ([Tools isEmpty:self.requirement]) {
                Selectcell.detailTextLabel.text = @"请选择";
            } else {
                Selectcell.detailTextLabel.text = self.requirement;
            }
            Selectcell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
        }
//        else if (indexPath.row == 3) {
//            TerminalTypeTableViewCell *terCell = [tableView dequeueReusableCellWithIdentifier:@"ter"];
//            [terCell setCheckBoxStatus:kProject.terminal_type];
//            terCell.checkBoxSelectionChanged = ^(NSString * _Nonnull data) {
//                kProject.terminal_type = data;
//            };
//            return terCell;
//        }
        else {
            Selectcell.textLabel.text = @"电源类型";
            if ([Tools isEmpty:self.power_type]) {
                Selectcell.detailTextLabel.text = @"请选择";
            } else {
                Selectcell.detailTextLabel.text = self.power_type;
            }
            Selectcell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
        }
        return Selectcell;
    }  else if (indexPath.row == 0) {
        if (![Tools isEmpty:self.owner_name]) {
            [cell setTitleStr:@"业主姓名" andColor:nil andHintStr:@"请修改业主的姓名" andInputViewIsHidden:NO andInfoStr:kProject.owner_name andUnit:nil];
            [cell setEditorText:self.owner_name];
        }
        else {
            [cell setTitleStr:@"业主姓名" andColor:nil andHintStr:@"请输入业主的姓名" andInputViewIsHidden:NO andInfoStr:nil andUnit:nil];
        }
        
        cell.TextFiledValueBlock = ^(NSString *value) {
            self.owner_name = value;
        };
        //        [cell setItemIsNesessory];
    }
    else if (indexPath.row == 1) {
        if (![Tools isEmpty:self.owner_tel]) {
            [cell setTitleStr:@"业主手机" andColor:nil andHintStr:@"请修改业主的联系手机号码" andInputViewIsHidden:NO andInfoStr:self.owner_tel andUnit:nil];
            [cell setEditorText:kProject.owner_tel];
        }
        else {
            [cell setTitleStr:@"业主手机" andColor:nil andHintStr:@"请输入业主的联系手机号码" andInputViewIsHidden:NO andInfoStr:nil andUnit:nil];
        }
        [cell setKeyboardType:UIKeyboardTypeNumberPad];
        cell.TextFiledValueBlock = ^(NSString *value) {
            self.owner_tel = value;
        };
        //        [cell setItemIsNesessory];
    }
    
    return cell;
}

- (void)cityName:(NSString *)name {
    self.city_name = name;
    [[DBManager manager]open:DB_Weather];
    self.city_id = [[DBManager manager]queryStringData:[NSString stringWithFormat:@"select Id from Cities WHERE Name = '%@'",name]];
    NSMutableDictionary *city = [NSMutableDictionary new];
    [city setObject:name forKey:@"city"];
    [city setObject:self.city_id forKey:@"id"];
    [Tools saveApplicationData:city forKey:CityName];
    [self.tableView reloadRowsAtIndexPaths:indexPathObj(4, 0) withRowAnimation:UITableViewRowAnimationAutomatic];
}

-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    [tableView deselectRowAtIndexPath:indexPath animated:YES];
    if (indexPath.section == 0) {
        if (indexPath.row == 3) {
            if ([Tools isEmpty:self.project_id]) {
                [self selectHouseFloors];
            }
        } else if (indexPath.row == 4) {
            //选择地点
            if ([Tools isEmpty:self.project_id]) {
                JFCityViewController *cityViewController = [[JFCityViewController alloc] init];
                //  设置代理
                cityViewController.delegate = self;
                cityViewController.title = @"城市";
                //  给JFCityViewController添加一个导航控制器
                UINavigationController *navigationController = [[UINavigationController alloc] initWithRootViewController:cityViewController];
                [navigationController.navigationBar setTintColor:[UIColor whiteColor]];
                [self presentViewController:navigationController animated:YES completion:nil];
            }
        } else if (indexPath.row == 5) {
            //选择项目需求
            if ([Tools isEmpty:self.project_id]) {
                [self selectRequirement];
            }
        }
//        else if (indexPath.row == 3) {
//            //选择项目类型
//            //            [self selectTerminalType];
//        }
        else if (indexPath.row == 6){
            //选择电源类型
            if ([Tools isEmpty:self.project_id]) {
                [self selectPowerType];
            }
        }
        
    }
}

-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
    static NSString *identifier = @"ProjectStep1Cell";
    EditorTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:identifier];
    if (cell == nil) {
        cell = [[EditorTableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:identifier];
        //cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
    }
    return [cell getHeight];
}

- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section {
    return [[UIView alloc]initWithFrame:CGRectMake(0, 0, kScreen_Width, DEFAULT_SECTION_HEIGHT)];
}

-(CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{
    return DEFAULT_SECTION_HEIGHT;
}
- (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section {
    return [[UIView alloc]initWithFrame:CGRectMake(0, 0, kScreen_Width, CGFLOAT_MIN)];
}
- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section{
    return CGFLOAT_MIN;
}

- (void)selectHouseFloors {
    UIAlertController * alertController = [UIAlertController alertControllerWithTitle: @"选择建筑层数" message: nil preferredStyle:UIAlertControllerStyleActionSheet];
    [alertController addAction: [UIAlertAction actionWithTitle:@"一层" style: UIAlertActionStyleDefault handler:^(UIAlertAction *action) {
        self.house_floors = 1;
        [self.tableView reloadRowsAtIndexPaths:indexPathObj(3, 0) withRowAnimation:UITableViewRowAnimationAutomatic];
    }]];
    [alertController addAction: [UIAlertAction actionWithTitle:@"二层" style: UIAlertActionStyleDefault handler:^(UIAlertAction *action) {
        self.house_floors = 2;
        [self.tableView reloadRowsAtIndexPaths:indexPathObj(3, 0) withRowAnimation:UITableViewRowAnimationAutomatic];
    }]];
    [alertController addAction: [UIAlertAction actionWithTitle:@"多层" style: UIAlertActionStyleDefault handler:^(UIAlertAction *action) {
        self.house_floors = 3;
        [self.tableView reloadRowsAtIndexPaths:indexPathObj(3, 0) withRowAnimation:UITableViewRowAnimationAutomatic];
    }]];
    [alertController addAction: [UIAlertAction actionWithTitle: @"取消" style: UIAlertActionStyleCancel handler:nil]];
    [self presentViewController: alertController animated: YES completion: nil];
}

- (void)selectPowerType {
    UIAlertController * alertController = [UIAlertController alertControllerWithTitle: @"选择电源类型" message: nil preferredStyle:UIAlertControllerStyleActionSheet];
    [alertController addAction: [UIAlertAction actionWithTitle:@"220V" style: UIAlertActionStyleDefault handler:^(UIAlertAction *action) {
        self.power_type = @"220V";
        [self.tableView reloadRowsAtIndexPaths:indexPathObj(6, 0) withRowAnimation:UITableViewRowAnimationAutomatic];
    }]];
    [alertController addAction: [UIAlertAction actionWithTitle:@"380V" style: UIAlertActionStyleDefault handler:^(UIAlertAction *action) {
        self.power_type = @"380V";
        [self.tableView reloadRowsAtIndexPaths:indexPathObj(6, 0) withRowAnimation:UITableViewRowAnimationAutomatic];
    }]];
    [alertController addAction: [UIAlertAction actionWithTitle:@"全部设备" style: UIAlertActionStyleDefault handler:^(UIAlertAction *action) {
        self.power_type = @"全部设备";
        [self.tableView reloadRowsAtIndexPaths:indexPathObj(6, 0) withRowAnimation:UITableViewRowAnimationAutomatic];
    }]];
    [alertController addAction: [UIAlertAction actionWithTitle: @"取消" style: UIAlertActionStyleCancel handler:nil]];
    [self presentViewController: alertController animated: YES completion: nil];
}

- (void)selectRequirement {
    UIAlertController * alertController = [UIAlertController alertControllerWithTitle: @"选择项目需求" message: nil preferredStyle:UIAlertControllerStyleActionSheet];
    [alertController addAction: [UIAlertAction actionWithTitle:@"空调" style: UIAlertActionStyleDefault handler:^(UIAlertAction *action) {
        self.requirement = @"空调";
        kProject.terminal_type = @"风机盘管";
        [self.tableView reloadRowsAtIndexPaths:indexPathObj(5, 0) withRowAnimation:UITableViewRowAnimationAutomatic];
    }]];
    [alertController addAction: [UIAlertAction actionWithTitle:@"采暖" style: UIAlertActionStyleDefault handler:^(UIAlertAction *action) {
        self.requirement = @"采暖";
        kProject.terminal_type = @"地暖";
        [self.tableView reloadRowsAtIndexPaths:indexPathObj(5, 0) withRowAnimation:UITableViewRowAnimationAutomatic];
    }]];
    [alertController addAction: [UIAlertAction actionWithTitle:@"空调+采暖" style: UIAlertActionStyleDefault handler:^(UIAlertAction *action) {
        self.requirement = @"空调+采暖";
        kProject.terminal_type = @"风机盘管+地暖";
        [self.tableView reloadRowsAtIndexPaths:indexPathObj(5, 0) withRowAnimation:UITableViewRowAnimationAutomatic];
    }]];
    [alertController addAction: [UIAlertAction actionWithTitle: @"取消" style: UIAlertActionStyleCancel handler:nil]];
    [self presentViewController: alertController animated: YES completion: nil];
}

//
//-(void)selectTerminalType {
//    CustomIOSAlertView *alert = [[CustomIOSAlertView alloc] init];
//    [alert setCloseOnTouchUpOutside:YES];
//    [alert setUseMotionEffects:YES];
//
//    UIView *subView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, kScreen_Width*2/3 + 40, 130)];
//
//    //标题栏
//    UIView *titleView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, subView.width, 50)];
//    [titleView setUserInteractionEnabled:YES];
//
//    titleView.backgroundColor = CM_DARKGREEN_COLOR;
//    [subView addSubview:titleView];
//    //左上角、右上角圆角为7
//    UIBezierPath *maskPath = [UIBezierPath bezierPathWithRoundedRect:titleView.bounds byRoundingCorners:UIRectCornerTopLeft|UIRectCornerTopRight cornerRadii:CGSizeMake(7, 7)];
//    CAShapeLayer *maskLayer = [[CAShapeLayer alloc] init];
//    maskLayer.frame = titleView.bounds;
//    maskLayer.path = maskPath.CGPath;
//    titleView.layer.mask = maskLayer;
//
//    //添加文字
//    UILabel *titleLabel = [UILabel labelSingleLineFontSize:14 content:@"选择末端类型"];
//    titleLabel.textColor = [UIColor whiteColor];
//    titleLabel.centerY = titleView.centerY;
//    titleLabel.centerX = titleView.centerX;
//    [titleView addSubview:titleLabel];
//
//    CheckBoxView *box1 = [[CheckBoxView alloc]initWithFrame:CGRectMake(0, CGRectGetMaxY(titleView.frame), subView.width, 40)];
//    BOOL status = NO;
//    if (![Tools isEmpty:kProject.terminal_type]
//        &&[kProject.terminal_type containsString:@"风机盘管"]) {
//        status = YES;
//    }
//    [box1 setCheckBoxTitle:@"风机盘管" andStatus:status];
//    box1.statusChanged = ^(BOOL isChecked) {
//        if (isChecked) {
//            if ([Tools isEmpty:kProject.terminal_type]) {
//                kProject.terminal_type = @"风机盘管";
//            } else {
//                kProject.terminal_type = [NSString stringWithFormat:@"%@+风机盘管", kProject.terminal_type];
//            }
//        } else {
//            if (![Tools isEmpty:kProject.terminal_type]) {
//                if ([kProject.terminal_type containsString:@"+风机盘管"]) {
//                    kProject.terminal_type = [kProject.terminal_type stringByReplacingOccurrencesOfString:@"+风机盘管" withString:@""];
//                } else {
//                    kProject.terminal_type = [kProject.terminal_type stringByReplacingOccurrencesOfString:@"风机盘管" withString:@""];
//                }
//            }
//        }
//
//    };
//    [subView addSubview:box1];
//
//    CheckBoxView *box2 = [[CheckBoxView alloc]initWithFrame:CGRectMake(0, CGRectGetMaxY(box1.frame), subView.width, 40)];
//    status = NO;
//    if (![Tools isEmpty:kProject.terminal_type]
//        &&[kProject.terminal_type containsString:@"地暖"]) {
//        status = YES;
//    }
//    [box2 setCheckBoxTitle:@"地暖" andStatus:status];
//    box2.statusChanged = ^(BOOL isChecked) {
//        if (isChecked) {
//            if ([Tools isEmpty:kProject.terminal_type]) {
//                kProject.terminal_type = @"地暖";
//            } else {
//                kProject.terminal_type = [NSString stringWithFormat:@"%@+地暖", kProject.terminal_type];
//            }
//        } else {
//            if (![Tools isEmpty:kProject.terminal_type]) {
//                if ([kProject.terminal_type containsString:@"+地暖"]) {
//                    kProject.terminal_type = [kProject.terminal_type stringByReplacingOccurrencesOfString:@"+地暖" withString:@""];
//                } else {
//                    kProject.terminal_type = [kProject.terminal_type stringByReplacingOccurrencesOfString:@"地暖" withString:@""];
//                }
//            }
//        }
//
//    };
//    [subView addSubview:box2];
//
//    [alert setContainerView:subView];
//    [alert setButtonTitles:@[@"确定", @"取消"]];
//    [alert setOnButtonTouchUpInside:^(CustomIOSAlertView *alertView, int buttonIndex) {
//        switch (buttonIndex) {
//            case 1:
//
//                break;
//            case 0:
//            {
//
//            }
//                break;
//            default:
//                break;
//        }
//    }];
//
//    [alert show];
//}

@end
